// Copyright (C) 2008 Taylor L. Riche <riche@cs.utexas.edu>
//  
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//

#ifndef MONITORREQUEST_H_
#define MONITORREQUEST_H_

#include <iostream>

namespace lagniappe
{
	
const std::string MONITOR_IN_PORT = "LC_monitor_IN";
const std::string MONITOR_OUT_PORT = "LC_monitor_OUT";

const unsigned long STRING_LENGTH = 16;


enum ReqType {MORE_RESOURCES, INIT_PROC, SET_SLAVE};
enum RespType {ADD_PROC, REVOKE_PROC, RESOURCES_EXHAUSTED};

class ProcElement;
class Operator;
class System;
std::string mon_debug(Operator * o, ReqType rt);
std::string mon_debug(Operator * o, RespType rt);

struct MonitorRequest
{
	Operator * op;
	ReqType msgType;
	union ReqBody {
		struct MoreResources {
			unsigned long load;
		} moreResources;
		struct InitProc {
			ProcElement * proc;
		} initProc;
		struct SetSlave {
			char procName[STRING_LENGTH];
		} setSlave;
	} reqBody;
};

struct SerialMonitorRequest
{
	char opName[STRING_LENGTH];
	ReqType msgType;
	union ReqBody {
		struct MoreResources {
			unsigned long load;
		} moreResources;
		struct InitProc {
			char procName[STRING_LENGTH];
		} initProc;
		struct setSlave {
			char procName[STRING_LENGTH];
		} setSlave;
	} reqBody;
	SerialMonitorRequest() {}
	SerialMonitorRequest(MonitorRequest & mr);
	MonitorRequest * genNativeMonitorRequest(System * sys);
};

struct MonitorResponse
{
	RespType msgType;
	union RespBody {
		struct AddProc {
			ProcElement * newProc;
		} addProc;
		struct RevokeProc {
			ProcElement * revokedProc;
		} revokeProc;
	} respBody;
};

}

#endif /*MONITORREQUEST_H_*/
